//
//  CarDetailPrintCell.m
//  New_Runway
//
//  Created by mack on 2018/1/25.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "CarDetailPrintCell.h"
#import "HomeWebviewLoadingController.h"
@interface CarDetailPrintCell ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *firstW;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *secondW;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *threeW;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *fourW;
@property (weak, nonatomic) IBOutlet UILabel *firstL;
@property (weak, nonatomic) IBOutlet UILabel *secondL;
@property (weak, nonatomic) IBOutlet UILabel *fourL;
@end

@implementation CarDetailPrintCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.firstW.constant = self.secondW.constant = self.threeW.constant = self.fourW.constant = Screen_width/4;
    

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setCarInfo:(CarResult *)carInfo{
    _carInfo = carInfo;
    if (_carInfo.carAuthState == 10 && _carInfo.carSaleState == 20) {//认证已上架
        self.firstW.constant = self.secondW.constant = self.threeW.constant = self.fourW.constant = Screen_width/4;

    }else if (_carInfo.carAuthState == 10 && _carInfo.carSaleState != 20){//认证未上架
        self.firstW.constant = self.threeW.constant = self.fourW.constant = Screen_width/3;
        self.secondW.constant = 0;

    }else if (_carInfo.carAuthState != 10 && _carInfo.carSaleState == 20){//上架未认证
        self.firstW.constant =  self.secondW.constant = self.fourW.constant = Screen_width/3;
        self.threeW.constant = 0;
    }
    [self setBorderWithView:self.fourL top:NO left:YES bottom:NO right:NO borderColor:UIColorHex(0xe1e1e1) borderWidth:0.5];
    [self setBorderWithView:self.firstL top:NO left:NO bottom:NO right:YES borderColor:UIColorHex(0xe1e1e1) borderWidth:0.5];
    [self setBorderWithView:self.secondL top:NO left:NO bottom:NO right:YES borderColor:UIColorHex(0xe1e1e1) borderWidth:0.5];
}
- (IBAction)previewWebBtn:(id)sender {
    NSString *shopID;
    if ([NRWCarUser sharedUser].shopId) {
        shopID = [NRWCarUser sharedUser].shopId;
    }else{
        shopID = @"";
    }
    NSString *url = [NSString stringWithFormat:@"%@/mshop/src/cars_detial.html?marketId=%@&shopId=%@&imgUrl=%@&carId=%@",Api,[NRWCarUser sharedUser].marketId,shopID,ImageApi,_carInfo.carId];
    [self pushWebView:url title:@"扫码后预览"];
    
}
- (IBAction)priceCodePreview:(id)sender {
    NSString *url = [NSString stringWithFormat:@"%@/cars/src/pricetag.html?carId=%@",Api,_carInfo.carId];
    [self pushWebView:url title:@"价签预览"];
}
-(void)pushWebView:(NSString *)url title:(NSString *)title{
    HomeWebviewLoadingController *webView = [[HomeWebviewLoadingController alloc] init];
    webView.urlstr = url;
    webView.mainTitle = title;
    [self.nav pushViewController:webView animated:YES];
    
}
- (IBAction)previewCertificate:(id)sender {
 
    NSString *url = [NSString stringWithFormat:@"%@/cars/src/cert.html?carId=%@",Api,_carInfo.carId];
    [self pushWebView:url title:@"证书预览"];

}

- (IBAction)PrintCode:(id)sender {
    if (_isShow == NO) {
        _isShow = YES;
    }else{
        _isShow = NO;
    }
    self.showBlock(_isShow);

}
- (void)setBorderWithView:(UIView *)view top:(BOOL)top left:(BOOL)left bottom:(BOOL)bottom right:(BOOL)right borderColor:(UIColor *)color borderWidth:(CGFloat)width{
    if (top) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, 0, view.frame.size.width, width);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    if (left) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, 0, width, view.frame.size.height);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    if (bottom) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, view.frame.size.height - width, view.frame.size.width, width);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    if (right) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(view.frame.size.width - width, 0, width, view.frame.size.height);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    
}
@end
